﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

namespace Opdacht_3
{
    public partial class _Default : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@"App_Data\Databank.mdb") + ";Persist Security Info=False";
            OleDbConnection dbconnectie = new OleDbConnection(strConn);

            OleDbCommand cmd = new OleDbCommand("SELECT teachername, classroom, subject FROM teachers WHERE teachername = @teachername", dbconnectie);
            cmd.Parameters.AddWithValue("@teachername", txt_naam.Text);

            string naam = "";
            string klaslokaal = "";
            string vak = "";
            

            dbconnectie.Open();

            OleDbDataReader dbread = cmd.ExecuteReader();

            while (dbread.Read())
            {
                
                naam = dbread["teachername"].ToString();
                klaslokaal = dbread["classroom"].ToString();
                vak = dbread["subject"].ToString();

                txt_naam.Text = naam;
                txt_klas.Text = klaslokaal;
                txt_vak.Text = vak;
            }
            dbconnectie.Close();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@"App_Data\Databank.mdb") + ";Persist Security Info=False";
            OleDbConnection dbconnectie = new OleDbConnection(strConn);

            //OleDbCommand cmd = new OleDbCommand("UPDATE teachers set classroom = @classroom AND subject = @subject WHERE teachername = @teachername", dbconnectie);
            OleDbCommand cmd = new OleDbCommand("UPDATE teachers SET classroom = @classroom, subject = @subject WHERE teachername = @teachername", dbconnectie);


            cmd.Parameters.AddWithValue("@classroom", txt_klas.Text);
            
            
            cmd.Parameters.AddWithValue("@subject", txt_vak.Text);

            cmd.Parameters.AddWithValue("@teachername", txt_naam.Text);

            dbconnectie.Open();

            cmd.ExecuteNonQuery();

            dbconnectie.Close();
        }

        protected void btn_naamverwijder_Click(object sender, EventArgs e)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@"App_Data\Databank.mdb") + ";Persist Security Info=False";
            OleDbConnection dbconnectie = new OleDbConnection(strConn);
            OleDbCommand cmd = new OleDbCommand("DELETE FROM teachers WHERE teachername = @teachername", dbconnectie);

            dbconnectie.Open();

            cmd.Parameters.AddWithValue("@teachername", txt_naam.Text);
            cmd.ExecuteNonQuery();

            dbconnectie.Close();
        }
    }

}

